/*
 * File:   Ackley.h
 * Author: jcrada
 *
 * Created on 26 May 2011, 12:58 PM
 */

#ifndef ECB_ACKLEY_H
#define	ECB_ACKLEY_H

#include "ecb/base/Problem.h"
#include <cmath>
namespace ecb {

    class Ackley : public Problem {
    public:

        Ackley(const std::string& id = "Ackley", const std::string& name = "Ackley",
                int dimensions = 0, scalar minimum = -32.768, scalar maximum = 32.768,
                bool minimization = true) :
        Problem(id, name, dimensions, minimum, maximum, minimization) { }

        scalar f(const std::vector<scalar>& x) {
            scalar sumA = 0.0, sumB = 0.0;
            for (size_t i = 0; i < x.size(); ++i) {
                sumA += x[i] * x[i];
                sumB += cos(2 * M_PI * x[i]);
            }
            return -20 * exp(-0.2 * std::sqrt((1.0 / x.size()) * sumA))
                    - exp((1.0 / x.size()) * sumB)
                    + 20 + M_E;
        }
    };
}

#endif	/* ECB_ACKLEY_H */

